﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;

namespace Arch.Data
{
    public interface IRepository<T> where T : class, new()
    {
        T Load(object id);
        T Create(T entity);
        T Attach(T entity, bool modified = false);
        T Detach(T entity);
        T Delete(T entity);
        T Update(T entity);
        T GetOrCreate(Expression<Func<T, bool>> expression);
        IEnumerable<T> Find(Expression<Func<T, bool>> expression = null, string order = null, int? max = null, int? page = null, bool? postorder = false);
        T FindOne(Expression<Func<T, bool>> expression = null);
        int Count(Expression<Func<T, bool>> expression = null);
        T New();
        IQueryable<T> GetQuery();

        string DefaultOrder { get; set; }
        bool IsPostOrder { get; set; }
    }

    public interface IRepository
    {
        T Load<T>(object id) where T : class, new();
        T Create<T>(T entity) where T : class, new();
        T Attach<T>(T entity, bool modified = false) where T : class, new();
        T Detach<T>(T entity) where T : class, new();
        T Delete<T>(T entity) where T : class, new();
        T Update<T>(T entity) where T : class, new();
        T GetOrCreate<T>(Expression<Func<T, bool>> expression = null) where T : class, new();
        IEnumerable<T> Find<T>(Expression<Func<T, bool>> expression = null, string order = null, int? max = null, int? page = null, bool? postorder = false) where T : class, new();
        T FindOne<T>(Expression<Func<T, bool>> expression = null) where T : class, new();
        int Count<T>(Expression<Func<T, bool>> expression = null) where T : class, new();
        T New<T>() where T : class, new();
        IQueryable<T> GetQuery<T>() where T : class, new();
        void SaveChanges();
    }
}
